package vip.meeet.lifecycle;

import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyValues;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;

import java.beans.PropertyDescriptor;

public class InstantiationAwareBeanPostProcessorBean implements InstantiationAwareBeanPostProcessor {

	private static final String thisClassName = InstantiationAwareBeanPostProcessor.class.getName();
	
	@Override
	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
		System.out.println(LifeCycleBean.sequence.getAndIncrement() + " " + thisClassName + "#"  + "postProcessBeforeInitialization");
		return bean;
	}

	@Override
	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
		System.out.println(LifeCycleBean.sequence.getAndIncrement() + " " + thisClassName + "#"  + "postProcessAfterInitialization");
		return bean;
	}

	@Override
	public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
		System.out.println(LifeCycleBean.sequence.getAndIncrement() + " " + thisClassName + "#"  + "postProcessBeforeInstantiation");
		return null;
	}

	@Override
	public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {
		System.out.println(LifeCycleBean.sequence.getAndIncrement() + " " + thisClassName + "#"  + "postProcessAfterInstantiation");
		return false;
	}

	@Override
	public PropertyValues postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean,
			String beanName) throws BeansException {
		System.out.println(LifeCycleBean.sequence.getAndIncrement() + " " + thisClassName + "#"  + "postProcessPropertyValues");
		return pvs;
	}

}
